package com.hdu.controller.classManagement;

import com.hdu.entity.Exam;
import com.hdu.pojo.Grade;
import com.hdu.pojo.PageBean;
import com.hdu.pojo.Result;
import com.hdu.service.CaseService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * <p>
 * 学情实体类 前端控制器
 * </p>
 *
 * @author xiaobai
 * @since 2024-05-21
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "学情管理接口")
@RequestMapping("/case")
public class CaseController {

    private final CaseService caseService;

    @GetMapping
    public Result<PageBean<Grade>> page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit,
                       String id, String username, String prop, String order, String tID) {
        log.info("分页查询, 参数: {},{},{},{},{},{},{}", page, limit, id, username, prop, order, tID);
        //调用service分页查询
        PageBean<Grade> pageBean = caseService.page(page, limit, id, username, prop, order, tID);
        return Result.success(pageBean);
    }

    @GetMapping("/averageClass")
    public Result<List<Double>> averageClass(String tID) {
        log.info("班级平均分查询，ID: {}", tID);
        List<Double> gradeList = caseService.averageClass(tID);
        return Result.success(gradeList);
    }

    @GetMapping("/limitStudent")
    public Result<List<Integer>> limitStudent(String sID,String subject) {
        log.info("学生近期单科成绩查询: {},{}", sID,subject);
        List<Integer> gradeList = caseService.limitStudent(sID,subject);
        return Result.success(gradeList);
    }

    @GetMapping("/limitSubject")
    public Result<List<Exam>> averageSubject(String tID) {
        log.info("班级近期单科成绩查询，ID: {}", tID);
        List<Exam> examList = caseService.limitSubject(tID);
        return Result.success(examList);
    }
}
